package org.example.controller;

import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.example.Annoation.Log;
import org.example.common.Result;
import org.example.entity.Emp;
import org.example.entity.EmpQueryParam;
import org.example.entity.PageBean;
import org.example.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.Instant;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/TliasWebManager/emps")
public class EmpController {
    @Autowired
    private EmpService empService;
    @GetMapping
    public Result listEmpPage(EmpQueryParam param){
        log.info("分页参数：{}",param);
        PageBean pageBean = empService.empPage(param);
        return Result.success(pageBean);
    }

    @PostMapping
    @Log
    public Result addEmp(@RequestBody Emp emp){
        log.info("请求参数：{}",emp);
        empService.save(emp);
        return Result.success();
    }

    @DeleteMapping
    @Log
    public Result deleteEmps(List<Integer> ids){
        log.info("请求参数: {}",ids);
        empService.deleteEmpsByIds(ids);
        return Result.success();
    }

    //根据ID查询员工信息
    @GetMapping("/{id}")
    public Result getEmpMsgById(@PathVariable Integer id){
        Emp emp = empService.selectEmpMsgById(id);
        return Result.success(emp);
    }

    //修改员工信息
    @PutMapping
    @Log
    public Result updateEmp(@RequestBody Emp emp){
        empService.updateEmpMsg(emp);
        return Result.success();
    }
    //登录
    @GetMapping("/login")
    public Result login(@RequestParam String username,@RequestParam String password){
        log.info("登录参数 {} {}",username,password);
        String token = empService.login(username,password);
        return Result.success(token);
    }

}
